finishsetup
<script type="text/javascript">

function saveSettings() { 			
 			localStorage["installDone"]='true';
 			
 			if(!import_chrome_history){
				localStorage["lastlocalsync"] = new Date().getTime();
			}else{
				localStorage["lastlocalsync"] = 0;
			}			
			
 			localStorage["username"]=username;
 			localStorage["password"]=password;
			localStorage["devicename"]=devicename;
			localStorage["server_url"]=server_url;
			localStorage["replace_chrome_history"]=replace_chrome_history;
			localStorage["wanted_devices"]=wanted_devices;
			localStorage["import_chrome_history"]=import_chrome_history;
			localStorage["sync_local_to_server"]=sync_local_to_server;
			localStorage["sync_server_to_local"]=sync_server_to_local;
						
			localStorage["lastDevicesSyncTimes"]="{\""+devicename+"\":0}";
			
			localStorage["lastLocal2ServSync"]=0;
			
			bg.insertdevice(devicename);			
}

function finishSetup() {
	if (localStorage["import_chrome_history"] === "true") {
		//bg.dirtyPollLastWeek();
		//TODO: cause work dirtypoll lastLocal2ServSync cant be getted properly
	}	
	
	//first poll for local histoy sync
	bg.initSynchronisation();
}

//create user
function create_account() {
    $('#info').fadeOut(0);
    $('#info').fadeIn(300).html('Contacting Server for Account creation...');
    try {
        $.post(server_url, {
            c: 2,
            u: username,
            p: bg.getHash(password),
            d: devicename
        }, function (data) {
        	$('#info').fadeOut(0);
            $('#info').fadeIn(300).html(data);
            try {
            	
                var json_obj = $.parseJSON(data);              
                switch (json_obj.code) {
                case 0:
                    //success
                    $('#info').fadeOut(0);
                    $('#info').fadeIn(300).html('Setup was succesfully finished.');
                    $('#content').fadeOut(300);
                    $('#header').fadeOut(300);

                    saveSettings();
                    finishSetup();							
                    break;

                case 1:
                    //general error
                    $('#info').fadeOut(0);
                    $('#info').fadeIn(300).html('Unknown Error, setup couldnt be finished.');
                    break;

                case 2:
                    //general error
                    $('#info').fadeOut(0);
                    $('#info').fadeIn(300).html('Account couldnt be created, setup couldnt be finished.');
                    break;
 				case 4:
                	//general error
                 	//$('#info').fadeOut(0);
                    //$('#info').fadeIn(300).html('Account couldnt be created, setup couldnt be finished.');
               		//console.log('create_account: error code: 4:'+json_obj.err);
               		
               		
               		break;  
                default:
                    break;
                }
            } catch (err) {
                //general error
                $('#info').fadeOut(0);
                $('#info').fadeIn(300).html($('#info').html()+'Very Unknown Error, setup couldnt be finished: ' + err);
            }
        });
    } catch (err) {
        //general error
        $('#info').fadeOut(0);
        $('#info').fadeIn(300).html('HTTP Post Error: ' + err);
    }
}

$('#button_finish').click(function(){				
			replace_chrome_history="true";
			wanted_devices="["+"\""+devicename+"\""+"]";			
			import_chrome_history = $('#import:checked').val();
			sync_local_to_server = $('#sync_local_to_serv:checked').val();
			sync_server_to_local = $('#sync_serv_to_local:checked').val();
			create_account(); 		
	});	


</script>

<div id="content0">	
	
	<table>	
	<tr><td>
	General Options:
	</td></tr>
	<tr><td>
	<input type=checkbox id="import" value="true" checked="checked"> Import Chrome History until now
	</td></tr>
	<tr><td>
	<br />
	</td></tr>
	<tr><td>
	Synchronisation Options:
	</td></tr>
	<tr><td>
	<input type=checkbox id="sync_local_to_serv" value="true" checked="checked"> Sync Local-History Changes to Server
	</td></tr>
	<tr><td>
	<input type=checkbox id="sync_serv_to_local" value="true" checked="checked"> Sync Server-History Changes to Local
	</td></tr>
	<tr><td>
	<input type="button" id="button_finish" value="Finish Setup"></button>
	</td></tr>
	</table>	
	
</div>